home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / progre1a / frmprogr.frm (.txt) next >
Encoding:
Visual Basic Form  |  1999-07-29  |  4.8 KB  |  146 lines

  1. VERSION 5.00
  2. Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX"
  3. Begin VB.Form frmProgress 
  4.    ClientHeight    =   1500
  5.    ClientLeft      =   48
  6.    ClientTop       =   48
  7.    ClientWidth     =   4464
  8.    ControlBox      =   0   'False
  9.    LinkTopic       =   "Form1"
  10.    ScaleHeight     =   1500
  11.    ScaleWidth      =   4464
  12.    ShowInTaskbar   =   0   'False
  13.    StartUpPosition =   3  'Windows Default
  14.    Begin MSComctlLib.ProgressBar prgDatabase 
  15.       Height          =   312
  16.       Left            =   120
  17.       TabIndex        =   3
  18.       Top             =   1080
  19.       Width           =   4272
  20.       _ExtentX        =   7535
  21.       _ExtentY        =   550
  22.       _Version        =   393216
  23.       Appearance      =   1
  24.       Scrolling       =   1
  25.    End
  26.    Begin MSComctlLib.ProgressBar prgTable 
  27.       Height          =   312
  28.       Left            =   120
  29.       TabIndex        =   2
  30.       Top             =   420
  31.       Width           =   4272
  32.       _ExtentX        =   7535
  33.       _ExtentY        =   550
  34.       _Version        =   393216
  35.       Appearance      =   1
  36.       Scrolling       =   1
  37.    End
  38.    Begin VB.Label lblDatabaseProgress 
  39.       Caption         =   "Database progress"
  40.       Height          =   192
  41.       Left            =   120
  42.       TabIndex        =   1
  43.       Top             =   840
  44.       Width           =   1512
  45.    End
  46.    Begin VB.Label lblTableTableProgress 
  47.       AutoSize        =   -1  'True
  48.       Height          =   192
  49.       Left            =   120
  50.       TabIndex        =   0
  51.       Top             =   120
  52.       Width           =   36
  53.    End
  54. Attribute VB_Name = "frmProgress"
  55. Attribute VB_GlobalNameSpace = False
  56. Attribute VB_Creatable = False
  57. Attribute VB_PredeclaredId = True
  58. Attribute VB_Exposed = False
  59. Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
  60. Private Sub Form_Click()
  61.   Unload Me
  62. End Sub
  63. Private Sub Form_Load()
  64.   Dim mDB As Database
  65.   Dim mRS(3) As Recordset
  66. '  Dim TableNames
  67.   'Center the screen and display it
  68.   frmProgress.Left = (Screen.Width - frmProgress.Width) / 2
  69.   frmProgress.Top = (Screen.Height - frmProgress.Height) / 2
  70.   frmProgress.Show
  71.   MsgBox "Click ok to start the program", vbOKOnly + vbInformation
  72.   frmProgress.MousePointer = vbHourglass
  73.   'Create an array of the table names to assign to the mRS array
  74. '  TableNames = Array("Table1", "Operation", "Maintenance", "F1")
  75.   'Pass the total number of records in the database to initializeProgressBar
  76.   InitializeProgressBar GetTotalRecordCount(App.Path & "\MyDatabase97.mdb", TableNames)
  77.   'open the database for processing
  78.   Set mDB = DBEngine.Workspaces(0).OpenDatabase(App.Path & "\MyDatabase97.mdb")
  79.   'open the tables for processing
  80.   For i = LBound(mRS) To UBound(mRS)
  81.     Set mRS(i) = mDB.OpenRecordset("Table" & CStr(i + 1))
  82.   Next
  83.   ReadDatabase mRS
  84.   mDB.Close
  85.   frmProgress.MousePointer = vbNormal
  86.   MsgBox "Click on the form to exit program", vbOKOnly + vbInformation
  87. End Sub
  88. Private Sub lblDatabaseProgress_Click()
  89.   Unload Me
  90. End Sub
  91. Private Sub lblTableTableProgress_Click()
  92.   Unload Me
  93. End Sub
  94. Private Sub prgDatabase_Click()
  95.   Unload Me
  96. End Sub
  97. Private Sub prgTable_Click()
  98.   Unload Me
  99. End Sub
  100. Private Sub InitializeProgressBar(MaxValue As Long)
  101.   With frmProgress
  102.     .prgDatabase.Min = 0
  103.     .prgDatabase.Value = 0
  104.     If MaxValue = 0 Then MaxValue = 1
  105.     .prgDatabase.Max = MaxValue
  106.     .Refresh
  107.   End With
  108. End Sub
  109. Private Function GetTotalRecordCount(DatabaseName As String, TableNames) As Long
  110.   Dim lDb As Database
  111.   Dim lRs As Recordset
  112.   Dim i As Integer
  113.   Set lDb = DBEngine.Workspaces(0).OpenDatabase(DatabaseName)
  114.   For i = 1 To 4
  115.     Set lRs = lDb.OpenRecordset("Table" & CStr(i))
  116.     GetTotalRecordCount = GetTotalRecordCount + lRs.RecordCount
  117.     lRs.Close
  118.   Next
  119. End Function
  120. Private Sub ReadDatabase(mRS() As Recordset)
  121.   For i = LBound(mRS) To UBound(mRS)
  122.     With mRS(i)
  123.       'Make sure the table has records in it.
  124.       If .RecordCount > 0 Then
  125.         'Show user which table is being read
  126.         frmProgress.lblTableTableProgress.Caption = "Now loading " & .Name
  127.         frmProgress.Refresh
  128.         
  129.         'initialize the progress bar to 0 for the table
  130.         frmProgress.prgTable.Value = 0
  131.         'Make sure we are starting at the first location of the table
  132.         .MoveFirst
  133.         While Not .EOF
  134.           'Sleep is used just to simulate time elapsing for processing the data
  135.           Sleep 5
  136.           'Process your data from the table here.
  137.           .MoveNext
  138.           frmProgress.prgDatabase.Value = frmProgress.prgDatabase.Value + 1
  139.           frmProgress.prgTable.Value = .PercentPosition
  140.         Wend
  141.         mRS(i).Close
  142.       End If
  143.     End With
  144.   Next
  145. End Sub
  146.